package zzps.exeed.web;

import zzps.exeed.kernel.ExeedConfig;
import zzps.exeed.kernel.core.AppContext;
import zzps.exeed.kernel.config.Config;
import zzps.exeed.kernel.core.Plugin;
import zzps.exeed.kernel.holder.PandaHolder;
import zzps.exeed.web.annotation.Controller;
import zzps.exeed.web.handle.ControllerPandaBuilder;
import zzps.exeed.web.handle.HandlerManager;
import zzps.exeed.web.handle.argument.ModelMethodArgumentResolver;
import zzps.exeed.web.handle.argument.SimpleTypeMethodArgumentResolver;
import zzps.exeed.web.handle.argument.SpecialTypeMethodArgumentResolver;

public class WebPlugin implements Plugin {


    @Override
    public void start(AppContext context) {
        context.container().addPandaBuilder(Controller.class,new ControllerPandaBuilder());
        HandlerManager.get().addArgumentResolver(new ModelMethodArgumentResolver());
        HandlerManager.get().addArgumentResolver(new SimpleTypeMethodArgumentResolver());
        HandlerManager.get().addArgumentResolver(new SpecialTypeMethodArgumentResolver());
        ExeedConfig config = context.config();
        ServerProp serverProp = new ServerProp();
        Object o = config.get(ServerProp.PORT_KEY);
        if (o != null) {
            int port = Integer.parseInt((String) o);
            serverProp.setPort(port);
        }
        context.container().registerPanda(new PandaHolder<>(ServerProp.class,serverProp));
    }

    @Override
    public void stop() {

    }
}
